﻿using CIS.Client.Modules.Main.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;

namespace CIS.Client.Modules.Main.ViewModels
{
    public class MenuViewModel : BindableBase, INavigationAware
    {
        private readonly IRegionManager? _regionManager;
        public MenuViewModel(IRegionManager regionManager)
        {
            _regionManager= regionManager;
            //CreateMenuModels();
        }

        /// <summary>
        /// 需要绑定的菜单列表数据
        /// </summary>
        public List<MenuModel>? Menus { get; set; }


        private DelegateCommand<string>? _navigateCommand;
        /// <summary>
        /// 需要绑定的导航命令
        /// </summary>
        public DelegateCommand<string>? NavigateCommand
        {
            get { return _navigateCommand ?? new DelegateCommand<string>(Navigation); }
        }

        /// <summary>
        /// 初始化菜单数据
        /// </summary>
        //private void CreateMenuModels()
        //{
        //    Menus = new List<MenuModel>();

        //    MenuModel menu1 = new MenuModel { MenuName = "首页", MenuPath = "HomeView" };
        //    MenuModel menu2 = new MenuModel { MenuName = "操作", MenuPath = "OperationView" };
        //    MenuModel menu3 = new MenuModel { MenuName = "设置", MenuPath = "SetView" };

        //    MenuModel menu2_1 = new MenuModel { MenuName = "卡匣", MenuPath = "CassetteView" };
        //    MenuModel menu2_2 = new MenuModel { MenuName = "Port管理", MenuPath = "PortView" };
        //    MenuModel menu2_3 = new MenuModel { MenuName = "单元", MenuPath = "UnitView" };

        //    MenuModel menu3_1 = new MenuModel { MenuName = "手臂控制", MenuPath = "RobotControlView" };
        //    MenuModel menu3_2 = new MenuModel { MenuName = "手臂Flow", MenuPath = "RobotFlowView" };
        //    MenuModel menu3_3 = new MenuModel { MenuName = "产品管理", MenuPath = "" };

        //    menu2.MenuItems?.Add(menu2_1);
        //    menu2.MenuItems?.Add(menu2_2);
        //    menu2.MenuItems?.Add(menu2_3);

        //    menu3.MenuItems?.Add(menu3_1);
        //    menu3.MenuItems?.Add(menu3_2);
        //    menu3.MenuItems?.Add(menu3_3);

        //    Menus.Add(menu1);
        //    Menus.Add(menu2);
        //    Menus.Add(menu3);
        //}

        /// <summary>
        /// 导航命令处理方法
        /// </summary>
        /// <param name="bar"></param>
        private void Navigation(string menuItem)
        {
            if (!string.IsNullOrWhiteSpace(menuItem))
            {
                _regionManager?.RequestNavigate("MainRegion", menuItem);
            }
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            var a = navigationContext.GetType().Assembly;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            
        }
    }
}

